package ModelLayer;
import java.util.ArrayList;

/**Every DVD has a general description that is common to all copies.
 * But each Copy has attributes which help to disinguish the copies.
 */
public class Copy
{
  //Copy instace variables.
  private String serialNumber; //Serial number is unique.
  private String purchaseDate;
  private String purchasePrice;
  private boolean isRented;
  
  //Object references
  private Loan loan;

  /** CONSTRUCTOR */
  public Copy(String serialNumber, String purchaseDate, String purchasePrice)
  {
    this.serialNumber = serialNumber;
    this.purchaseDate = purchaseDate;
    this.purchasePrice = purchasePrice;
    isRented = false; //It is false because the copy is being created now/
  }
  
  /** ACCESSORS */
  public String getSerialNumber()
  {
      return serialNumber;
  }
  public String getPurchaseDate()
  {
      return purchaseDate;
  }
  public String getPurchasePrice()
  {
      return purchasePrice;
  }
  
  /** MUTATORS */
  public void setSerialNumber(String serialNumber)
  {
      this.serialNumber = serialNumber;
      //(1) A check is performed. If there is already a copy with the same
      //serialNumber this change will not be applied to this instance.
      //STEFO: I will implement this stuff soon.
  }
  
  public void setPurchaseDate(String purchaseDate)
  {
      this.purchaseDate = purchaseDate;
  }
  public void setPurchasePrice(String purchasePrice)
  {
      this.purchasePrice = purchasePrice;
  }  
  public void update( String purchaceDate, String purchasePrice)
  {
    setPurchaseDate(purchaseDate);
    setPurchasePrice(purchasePrice);
  }
  
  public String toString() //returns a string with all the data in a copy
    {
        
        String s="Serial Number=" + getSerialNumber()+'\n'+ "Purchase Price=" +getPurchasePrice()+'\n';
        s+="Purchase Date" + getPurchaseDate() + '\n' + "State: " +isRentedx() + '\n';
        return s;
        
    }
    public String isRentedx() // returns a string with state of the dvd... if it's rented or not
    { String s="";
        if(isRented)
        {
            s="Is rented by " + getLoan().getPerson().getName() + '\n';
        }
        else
        {
            s="Is not rented" + '\n';
        }
        return s;
    }
    
  //Methods for renting and returning a copy.
  public void rentCopy()
  {
      isRented = true;
  }
  public void unrentCopy()
  {
      isRented = false;
  }
  
  public boolean isRented() 
    {
        return isRented;
    }
  public Loan getLoan()
     {
         return loan;
     }
  
  public void  setLoan(Loan loan)
  {
      this.loan = loan;
  }
  public void deleteLoan()
  {
      loan = null;
  }
}
